*******************************************************************************

*Table A.9: Effects on determinants of beneficiary transaction costs
*This table reports estimated treatment effects on the costs incurred by beneffciaries to access PDS rations in March 2017
*******************************************************************************



use "${SurveyDataDir}/JH_ePOS_HH_DataforAnalysis.dta",clear


count if ss_code == "ghost"
scalar ghosts = r(N)
keep if ss_code == "SS01" 
drop if ghost_final==1
svyset [pw = pweight]

scalar obs = 3960 


svyset [pw = pweight]

*******************************************************************************
* Cost to collect PDS ration per month (March)

***************************************
*Trip time
***************************************

count
scalar obs = 3960 

*successful trips
qui svy: mean c20a_success_time_hr_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo success_time: xi: reg c20a_success_time_hr_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

*unsuccessful trips
qui svy: mean c20a_unsuccess_time_hr_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo unsuccess_time: xi: reg c20a_unsuccess_time_hr_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs


***************************************
*total cost of access
***************************************
gen bl_var = c_cost_to_access_y0
egen bl_var_mean = mean(bl_var)
gen bl_var_mi = missing(bl_var)
replace bl_var = bl_var_mean if bl_var_mi == 1


scalar obs = 3960 - ghosts
qui svy: mean c_total_access_cost_adj_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)

*without Baseline 
eststo tot_costmar: xi: reg c_total_access_cost_adj_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

*without Baseline
eststo tot_costmarBL: xi: reg c_total_access_cost_adj_mar17 bl_var bl_var_mi treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs


***************************************
*Household opportunity cost
***************************************

scalar obs = 3960 - ghosts
qui svy: mean c21_c22_opcost_hr_wtdmean if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo opp_cost: xi: reg c21_c22_opcost_hr_wtdmean treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs


***************************************
* Number of unsuccessful trips by members
***************************************

scalar obs = 3960 - ghosts
qui svy: mean c19_20_unsuccess_trips_adj_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo unsucc_trips: xi: reg c19_20_unsuccess_trips_adj_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs


***************************************
*Number of successful of trips made by members
***************************************

count
scalar obs = 3960 - ghosts

qui svy: mean c20_success_trips_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo succ_trips: xi: reg c20_success_trips_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

***************************************
*Transaction Time
***************************************

count
scalar obs = 3960 - ghosts

qui svy: mean c12_transaction_time_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo transact_time_March: xi: reg c12_transaction_time_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs

***************************************
* Transportation cost
***************************************
count

scalar obs = 3960 - ghosts

qui svy: mean c_total_transport_cost_mar17 if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo transport: xi: reg c_total_transport_cost_mar17 treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs



***************************************
*Travel Time
***************************************

count
scalar obs = 3960 - ghosts

qui svy: mean c6_collect_time if treatment == 0 
qui estat sd
matrix Mean0 = r(mean)
eststo collect_time: xi: reg c6_collect_time treatment i.strata [pw = pweight], cluster(block_code)
estadd scalar control_mean = `=Mean0[1,1]'
estadd scalar percent_obs 100*e(N)/obs



#delimit ;
esttab tot_costmar tot_costmarBL opp_cost unsucc_trips unsuccess_time succ_trips success_time transport using "${OutputDir}/TableA_9.tex" , 
	label b(%12.2g) se(%12.2g) booktabs replace nocons nolz width(\hsize)
	drop(_cons _Istrata* bl_var_mi) 
	order (treatment)
	coeflabels( treatment "Treatment" bl_var "Baseline lag" )
	stats(r2_a control_mean N percent_obs, 
			labels("Adjusted R\textsuperscript{2}" "Control mean" "Observations" "\% of sample" 
				) fmt(2 %12.2g %15.0fc 0))
	star(* .10 ** .05 *** .01) 
	mgroups("\specialCellCenter{Total \\ Cost}" "\specialCellCenter{Opportunity \\cost}" "\specialCellCenter{Unsuccessful \\ trip count}" "\specialCellCenter{Unsuccessful \\ trip length}" "\specialCellCenter{Successful \\ trip count}" "\specialCellCenter{Successful \\ trip length}" "\specialCellCenter{Transport \\ cost}",	
			pattern(1 0 1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) 
			span erepeat(\cmidrule(lr){@span}))
	mlabel(none)
	substitute("Standard errors in parentheses" " "
				"\sym{*} \(p<.10\), \sym{**} \(p<.05\), \sym{***} \(p<.01\)" " "
				"\multicolumn{9}{l}{\footnotesize  }\\" " ");

				
				

#delimit cr 
eststo clear


